package agent

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserRebatesLeveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员返佣等级--修改
func NewUpdateUserRebatesLeveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserRebatesLeveLogic {
	return &UpdateUserRebatesLeveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserRebatesLeveLogic) UpdateUserRebatesLeve(req *types.UserRebatesLevelUpdateReq) (resp *types.IsSuccessInfo, err error) {

	rpcReq := &rpc.UpdateUserRebatesLevelReq{
		ID:            req.Id,
		UserID:        req.UserId,
		Level:         req.Level,
		FeeRate:       req.FeeRate,
		AvailableDays: req.AvailableDays,
	}
	report, err := l.svcCtx.AgentRPC.UpdateUserRebatesLevel(context.Background(), rpcReq)
	if err != nil {
		logx.Error(l.ctx, err)
		return nil, err
	}

	resp = &types.IsSuccessInfo{
		IsSuccess: report.IsSuccess,
	}

	return
}
